package com.ljk.studywebsocket.config3;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.ApplicationContext;
import org.springframework.context.annotation.Configuration;
import org.springframework.lang.NonNull;
import org.springframework.web.socket.WebSocketHandler;
import org.springframework.web.socket.handler.WebSocketHandlerDecoratorFactory;

/**
 * 事件处理器工厂类
 *
 * @author ljk
 * @since 2023-01-10 21:54
 */
@Configuration
public class MyHandlerFactory implements WebSocketHandlerDecoratorFactory {
    @Autowired
    private ApplicationContext applicationContext;

    /** 注册一个事件处理器 */
    @Override
    @NonNull
    public WebSocketHandler decorate(@NonNull WebSocketHandler handler) {
        return new MyHandler(handler).init(applicationContext);
    }

}